define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
//注入自定义js-切片上传文件到华为OBS
    function ZhuRuJS(url){
        let temp=document.createElement('script');
        temp.setAttribute('type','text/javascript');
        temp.src=url;
        document.head.appendChild(temp);
    }
    ZhuRuJS(location.origin+'/assets/js/common/slicesUpload.js');

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'cms/platepost/index' + location.search,
                    add_url: 'cms/platepost/add',
                    edit_url: 'cms/platepost/edit',
                    del_url: 'cms/platepost/del',
                    multi_url: 'cms/platepost/multi',
                    import_url: 'cms/platepost/import',
                    table: 'plate_post',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'postname', title: __('Postname'), operate: 'LIKE'},
                        // {field: 'file', title: __('File'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'accessory', title: __('Accessory'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
//                        {field: 'postcontent', title: __('Postcontent')},
                        {field: 'block_text', title: __('Plateid'),operate: false},
                        {field: 'username', title: __('Username'), operate: 'LIKE'},                        
                        {field: 'view', title: __('View'), operate: 'LIKE'},
                        {
                            field: 'is_jing',
                            title: __('Is_jing'),
                            align: 'center',
                            table: table,
                            searchList: {"0": __('否'), "1": __('是')},
                            formatter: Table.api.formatter.toggle
                        },
                        {
                            field: 'top',
                            title: __('Top'),
                            align: 'center',
                            table: table,
                            searchList: {"0": __('否'), "1": __('是')},
                            formatter: Table.api.formatter.toggle
                        },
                        {
                            field: 'is_audit',
                            title: __('Is_audit'),
                            align: 'center',
                            table: table,
                            searchList: {"0": __('否'), "1": __('是')},
                            formatter: Table.api.formatter.toggle
                        },
//                        {
//                            field: 'lock',
//                            title: __('Lock'),
//                            align: 'center',
//                            table: table,
//                            formatter: Table.api.formatter.toggle
//                        },

//                        {field: 'lock', title: __('Lock'), operate: 'LIKE'},
//                        {field: 'top', title: __('Top'), operate: 'LIKE'},
                        {field: 'replytime', title: __('Replytime'), operate:false, addclass:'datetimerange', autocomplete:false},
//                        {field: 'appid', title: __('Appid')},
                        {field: 'creat_time', title: __('Creat_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        
                        {field: 'membership_price', title: __('Membership_price')},
                        {field: 'membership_duration', title: __('Membership_duration')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
            $(document).on('click', '.btn-move', function () {
                var ids = Table.api.selectedids(table);
                Layer.open({
                    title: __('Move'),
                    content: Template("channeltpl", {}),
                    btn: [__('Move')],
                    yes: function (index, layero) {
                        var channel_id = $("select[name='channel']", layero).val();
                        if (channel_id == 0) {
                            Toastr.error(__('Please select channel'));
                            return;
                        }
                        Fast.api.ajax({
                            url: "cms/platepost/move/ids/" + ids.join(","),
                            type: "post",
                            data: {channel_id: channel_id},
                        }, function () {
                            table.bootstrapTable('refresh', {});
                            Layer.close(index);
                        });
                    },
                    success: function (layero, index) {
                    }
                });
            });
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
